var path = require('path')
var webpack = require('webpack')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var CleanWebpackPlugin = require('clean-webpack-plugin')

module.exports = {
  entry: {
    home: [
      './src/views/home-v2/home.js'
    ]
  },
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: '[name].bundle.js',
    chunkFilename: '[name].chunk.js',
  },
  module: {
    rules: [
      { // 样式文件加载
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      },
      { // less文件加载
        test: /\.less$/,
        use:[
          {
            loader: 'style-loader'
          },
          {
            loader: 'css-loader'
          },
          {
            loader: 'less-loader'
          }
        ]
      },
      { // js文件加载
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      { // 图片、字体资源加载
        test: /\.(png|jpg|gif|svg|ttf|eot|woff|woff2)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]',
          publicPath: '/images',
          outputPath: '/images'
        }
      },
      {
        test: /\.html$/,
        use: [{
          loader: 'html-loader',
        }]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(['dist']), // 清空di
    new webpack.optimize.UglifyJsPlugin({ // 压缩js文件
      sourceMap: false,
      compressor: {
        warnings: false,
      },
    }),
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery',
      'window.$': 'jquery',
    }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new HtmlWebpackPlugin({
      template: './src/views/home-v2/home.html'
    }),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify('production')
    })
  ]
}
